<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/28 0028
 * Time: 16:03
 */

namespace Cuke\Http;


use Cuke\Models\CukeAdmin;
use Phalcon\Mvc\Controller;

/**
 * 控制器基类
 * @package CukeDaojia\CukeManagement\Controllers
 * @property \Phalcon\Cache\BackendInterface $cache 缓存操作
 * @property \Phalcon\Logger\Multiple $logger 日志记录
 * @property array $config 配置
 * @property \Phalcon\Db\AdapterInterface $db
 * @property \Phalcon\Mvc\Dispatcher|\Phalcon\Mvc\DispatcherInterface $dispatcher
 * @property \Phalcon\Mvc\Router|\Phalcon\Mvc\RouterInterface $router
 * @property \Phalcon\Mvc\Url|\Phalcon\Mvc\UrlInterface $url
 * @property \Phalcon\Http\Request|\Phalcon\Http\RequestInterface $request
 * @property \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface $response
 * @property \Phalcon\Http\Response\Cookies|\Phalcon\Http\Response\CookiesInterface $cookies
 * @property \Phalcon\Filter|\Phalcon\FilterInterface $filter
 * @property \Phalcon\Flash\Direct $flash
 * @property \Phalcon\Flash\Session $flashSession
 * @property \Phalcon\Session\Adapter\Files|\Phalcon\Session\Adapter|\Phalcon\Session\AdapterInterface $session
 * @property \Phalcon\Events\Manager|\Phalcon\Events\ManagerInterface $eventsManager
 * @property \Phalcon\Security $security
 * @property \Phalcon\Crypt|\Phalcon\CryptInterface $crypt
 * @property \Phalcon\Tag $tag
 * @property \Phalcon\Escaper|\Phalcon\EscaperInterface $escaper
 * @property \Phalcon\Annotations\Adapter\Memory|\Phalcon\Annotations\Adapter $annotations
 * @property \Phalcon\Mvc\Model\Manager|\Phalcon\Mvc\Model\ManagerInterface $modelsManager
 * @property \Phalcon\Mvc\Model\MetaData\Memory|\Phalcon\Mvc\Model\MetadataInterface $modelsMetadata
 * @property \Phalcon\Mvc\Model\Transaction\Manager|\Phalcon\Mvc\Model\Transaction\ManagerInterface $transactionManager
 * @property \Phalcon\Assets\Manager $assets
 * @property \Phalcon\Di|\Phalcon\DiInterface $di
 * @property \Phalcon\Session\Bag|\Phalcon\Session\BagInterface $persistent
 * @property \Phalcon\Mvc\View|\Phalcon\Mvc\ViewInterface $view
 * @property \Redis $redis;
 * @property \League\Flysystem\Filesystem $storage 文件储存
 * @property \Cuke\Library\Snowflake\Snowflake $snowflake 分布式唯一ID生成
 * @property \Phalcon\Security\Random $random
 * @property \Phalcon\Acl\Adapter\Memory $acl
 */
class ControllerBase extends Controller
{
    const PageSize = 15;
    /**
     * @var CukeAdmin
     */
    protected $member;
    protected $role_code;


    public function initialize()
    {
        $admin = $this->session->get('member');
        if(empty($admin) === false){
            $admin = @unserialize($admin);
            if($admin){
                $this->member = $admin;
                $this->view->setVar('Member',$admin);
            }
        }

        $role_code = $this->session->get('RoleCode');
        $this->role_code = $role_code;

        $menu = new \stdClass();
        $menu->{$this->dispatcher->getControllerName()} = 'current';

        $this->view->setVar('Menu',$menu);

        $this->view->setVar('Role',$role_code);
        $this->view->setVar('Version',CUKE_VERSION);
    }

    /**
     * 是否是超级管理员
     * @return bool
     */
    public function isSuperAdministrator()
    {
        return $this->role_code == 'Administrators';
    }


}